package com.example.zm_fanjiantao.config;

import com.example.zm_fanjiantao.interceptor.Interceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Component
public class WebStaticConfig implements WebMvcConfigurer {
    @Value("${upload.path}")
    private String filePath;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("calsspath:/images/");
        registry.addResourceHandler("/view/**")
                .addResourceLocations("classpath:/images/");
        registry.addResourceHandler("/files/**")
                .addResourceLocations("file:"+filePath);

    }

//    注册拦截器
    @Resource
    private Interceptor interceptor;

    public void addInterceptors(InterceptorRegistry registry) {
         //默认拦截所有url
         registry.addInterceptor(interceptor);
    }



}
